package com.itheima;

import org.xml.sax.ext.Attributes2;

import javax.crypto.interfaces.PBEKey;
import java.security.PublicKey;
import java.util.zip.Adler32;

/**
 * @ProjectName: untitled
 * @Titile: TestLambda
 * @Author: 王亦凡1
 * @Description: TODO
 */
public class TestLambda {
    public static void main(String[] args) {
        testA();
        testB();
        testc();
        testD();

    }
    public static void  testD() {
        //1.创建D接口的匿名内部类
        D d1 = new D() {
            @Override
            public int max(int a, int b) {
                return a > b ? a : b;
            }
        };
        //2.创建D接口的lambda表达式
        D d2 = ( a, b)->  a > b ? a : b;
        //3.方法引用
        D d3=Math::max;
        int max=d3.max(1,2);
        System.out.println(max);


    }
    public static void testc(){
        //1.创建C接口的匿名内部类
        C c1=new C() {
            @Override
            public String show(String name) {
                return "name"+name;
            }
        };
        //2.创建C接口的lambda表达式
        C c2=name->"name"+name;
        //3.
        //2.创建C接口的方法引用
        C c3=TestLambda::show4;
        String result = c3.show("王德法");
        System.out.println(result);

    }
    public static String show4(String name){
        return name;
    }


    public static void testB(){
        //创建B接口的匿名名内部类对象
        B b1=new B() {
            @Override
            public void show(String name) {
                System.out.println(name);
            }
        };
        //创建B接口的lambda表达式
        B b2=name-> System.out.println(name);
        //创建B接口的方法引用
        B b3= System.out::println;
        b3.show("王彪");
    }
    public static void testA() {
        //1.创建A接口的匿名内部类对像
        A a1 = new A() {
            @Override
            public  void show(String name, int age) {
                System.out.println(name + "," + age);
            }
        };
        //2.将匿名内部类对象改成lambda表达式
        A a2 = ( name, age) ->
            System.out.println(name + "," + age);
          a2.show("张三",18);
    }
         //3.使用方法引用替换Lambda
        A a3=TestLambda::show2;


    //4.使用方法引用lambda表达式（成员方法）
    A a4=new TestLambda()::show3;

    //定义一个成员方法，故意让返回值和形参A中方法一致
    public static void show2(String name, int age) {
        System.out.println("show2:"+name+","+age);
    }

    public void show3(String name, int age) {
        System.out.println("show2:"+name+","+age);
    }


}
